package com.example.basic.web.controller.terminal;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.terminal.TerminalRecord;
import com.example.basic.web.service.terminal.TerminalRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "作业记录", tags = {"作业记录"})
@RestController
@RequestMapping("/api/v1/byg/terminal")
public class TerminalRecordController {

    @Resource
    private TerminalRecordService terminalRecordService;

    @Log(title = "作业记录", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<TerminalRecord>> queryList(
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "deviceName", value = "应用终端名称") @RequestParam(required = false) String deviceName,
            @ApiParam(name = "type", value = "1-队列，2-记录") @RequestParam(defaultValue = "1") String type,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<TerminalRecord> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(terminalRecordService.queryList(queryPage,pharmCode, zoneCode,depotCode,beginTime,endTime,deviceName,type));
    }

    @Log(title = "作业记录", description = "取消")
    @ApiOperation(value = "取消", notes = "取消")
    @PostMapping("/cancel")
    public Result<Boolean> cancel(
            @ApiParam(name = "id", value = "唯一id") @RequestParam String id ,
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam(required = false) String deviceCode) {
        return ResultGenerator.genSuccessResult(terminalRecordService.cancel(id,deviceCode));
    }

    @Log(title = "作业记录", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<Boolean> delete(@ApiParam(name = "id", value = "唯一id") @RequestParam String id ) {
        return ResultGenerator.genSuccessResult(terminalRecordService.delete(id));
    }

    @Log(title = "作业记录", description = "重发")
    @ApiOperation(value = "重发", notes = "重发")
    @PostMapping("/repeat")
    public Result<TerminalRecord> repeat(@ApiParam(name = "id", value = "唯一id") @RequestParam String id ) {
        return ResultGenerator.genSuccessResult(terminalRecordService.repeat(id));
    }

    @Log(title = "作业记录", description = "强制完成")
    @ApiOperation(value = "强制完成", notes = "强制完成")
    @PostMapping("/forceFinish")
    public Result<Boolean> forceFinish(
            @ApiParam(name = "id", value = "唯一id") @RequestParam String id ,
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam(required = false) String deviceCode) {
        return ResultGenerator.genSuccessResult(terminalRecordService.forceFinish(id,deviceCode));
    }
}
